package com.able.mmbs.util;

import android.text.TextUtils;
import android.util.Log;

import java.util.HashMap;
import java.util.Map;

public class TempretureProcessTool implements ProcessTool {

    private static String TAG = "TempretureProcessTool";
    private static String serviceUuid = "0000ffe5-0000-1000-8000-00805f9b34fb";
    private static String characteristic = "0000ffe8-0000-1000-8000-00805f9b34fb";


    @Override
    public String getServiceUuid() {
        return serviceUuid;
    }

    @Override
    public String getCharacteristicUuid() {
        return characteristic;
    }


    public static Map<String, Object> getValues(String src) {

// 29.5  10       AAAA A2 00 06 0127 0064 01 00 89 55
// 28.2  11       AAAA A2 00 06 011A 006E 01 00 86 55
        if(TextUtils.isEmpty(src)){
            Log.e(TAG, "src is empty");
            return null;
        }
        if(src.length()%2==1 || src.length()!=26){
            Log.e(TAG, "src is error");
            return null;
        }

        if(!src.toUpperCase().startsWith("AAAA")){
            Log.e(TAG, "src is error");
            return null;
        }
        if(!src.toUpperCase().startsWith("AAAA")){
            Log.e(TAG, "src is error");
            return null;
        }
        Map<String, Object> values = new HashMap<>(2);

        String temHex = src.substring(10,14);
        Log.i(TAG, "temHex: "+temHex);
        Integer tempreture = Integer.parseInt(temHex, 16);
        values.put("tempreture", tempreture);

        String humidityHex = src.substring(14,18);
        Log.i(TAG, "humidityHex: "+humidityHex);
        Integer humidity = Integer.parseInt(humidityHex, 16);
        values.put("humidity", humidity);

        return values;
    }


}
